package site.lanmushan.framework.mapper.util;

import lombok.extern.slf4j.Slf4j;
import site.lanmushan.framework.mapper.wrapper.FormatWrapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 */
@Slf4j
public class QueryWrapperUtil {
    public static String createWhereString(FormatWrapper queryWrapper) {
        String whereString=queryWrapper.getWhereString();
        if(whereString==null)
        {
            return "";
        }
        return whereString.replaceAll("\\{\\{alias}}",queryWrapper.getAlias());
    }
    public static String createWhereStringNull(FormatWrapper queryWrapper) {
        String whereString=queryWrapper.getWhereString();
        if(whereString==null)
        {
            return "";
        }
        return whereString.replaceAll("\\{\\{alias}}.","");
    }
    public static String createColumnsString(FormatWrapper queryWrapper) {
        List<String> list =queryWrapper.getColumns();
        List<String> resultList=new ArrayList<>(list.size());
        for (String col:list) {
            resultList.add(queryWrapper.getAlias()+"."+col);
        }
        return String.join(",",resultList);
    }
}
